package com.tongji.showroom.view
{
	import com.tongji.showroom.events.ReleaseProductEvent;
	import com.tongji.showroom.model.UserSceneModel;
	import com.tongji.showroom.view.titleWindows.PreviewSceneTitleWindow;
	import com.tongji.showroom.vo.SavePicture;
	
	import flash.display.BitmapData;
	import flash.events.MouseEvent;
	import flash.geom.Matrix;
	import flash.geom.Rectangle;
	import flash.net.FileReference;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.utils.ByteArray;
	
	import mx.graphics.codec.JPEGEncoder;
	import mx.managers.PopUpManager;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author yanghanbing
	 * 2011/08/
	 */ 
	public class ThirdStepMediator extends Mediator
	{
		[Inject]
		public var view:ThirdStepComp;
		
		[Inject]
		public var model:UserSceneModel;
		
		override public function onRegister():void
		{
			eventMap.mapListener(view.previewBtn, MouseEvent.CLICK, popUpPreviewHandler, MouseEvent);
			eventMap.mapListener(view.releaseSceneBtn, MouseEvent.CLICK, releaseSceneHandler, MouseEvent);
			view.releaseSceneBtn.selected = model.currentUserScene.state;
			//eventMap.mapListener(view.releaseSceneComp.downLoad, MouseEvent.CLICK, downLoadHandler, MouseEvent);
		}
		
		private function popUpPreviewHandler(event:MouseEvent):void
		{
			/*var titleWindow:PreviewSceneTitleWindow = new PreviewSceneTitleWindow();
			titleWindow = PreviewSceneTitleWindow(PopUpManager.createPopUp(view,PreviewSceneTitleWindow,true)); 
			titleWindow.title = "预览";
			PopUpManager.centerPopUp(titleWindow); 
			titleWindow.x = view.parent.width / 2;
			titleWindow.y = view.parent.height / 2 - 150;
			mediatorMap.createMediator(titleWindow.releaseComp);*/
			navigateToURL(new URLRequest("http://design.rryjw.com/showroomfront/showroomfront.html"), "_blank");
		}
		
		private function releaseSceneHandler(event:MouseEvent):void
		{
			dispatch(new ReleaseProductEvent(ReleaseProductEvent.RELEASE_A_PRODUCT, model.currentUserScene));
			/*if(view.releaseSceneBtn.selected)
			{
				model.currentUserScene.state = view.releaseSceneBtn.selected;
				dispatch(new ReleaseProductEvent(ReleaseProductEvent.RELEASE_A_PRODUCT, model.currentUserScene));
			}*/
		}
	}
}